<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="页面名称" prop="pageName">
        <el-input
          v-model="queryParams.pageName"
          placeholder="请输入页面名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>



      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:configInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:configInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:configInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:configInfo:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="页面名称" align="center" prop="pageName" />
      <el-table-column label="url" align="center" prop="url" />
      <el-table-column label="文件名" align="center" prop="fileName" />
      <el-table-column label="文件内容" align="center" prop="fileContent" />
      <el-table-column label="上传路径" align="center" prop="uploadPath" />
      <el-table-column label="创建时间" align="center" prop="createdDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="修改人" align="center" prop="updatedBy" />
      <el-table-column label="是否有配置，0未配置，1有配置" align="center" prop="isHaveConfig" />
      <el-table-column label="是否上传，0未上传1已上传" align="center" prop="uploadFlag" />
      <el-table-column label="是否确认过，0未确认1已确认" align="center" prop="confirmFlag" />
      <el-table-column label="发布内容" align="center" prop="publishText" />
      <el-table-column label="生产人姓名" align="center" prop="createdName" />
      <el-table-column label="修改人姓名" align="center" prop="updatedName" />
      <el-table-column label="业务线" align="center" prop="businessLine" />
      <el-table-column label="业务对接人" align="center" prop="businessContactPerson" />
      <el-table-column label="测试结果" align="center" prop="testResult" />
      <el-table-column label="页面描述" align="center" prop="pageDescription" />
      <el-table-column label="离线包url" align="center" prop="offlineUrl" />
      <el-table-column label="离线包名" align="center" prop="offline" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:configInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:configInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改适老化对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="应用id" prop="appId">
          <el-input v-model="form.appId" placeholder="请输入应用id" />
        </el-form-item>
        <el-form-item label="页面名称" prop="pageName">
          <el-input v-model="form.pageName" placeholder="请输入页面名称" />
        </el-form-item>
        <el-form-item label="url" prop="url">
          <el-input v-model="form.url" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件名" prop="fileName">
          <el-input v-model="form.fileName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件内容">
          <editor v-model="form.fileContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="上传路径" prop="uploadPath">
          <el-input v-model="form.uploadPath" placeholder="请输入上传路径" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createdDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="修改人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="是否有配置，0未配置，1有配置" prop="isHaveConfig">
          <el-input v-model="form.isHaveConfig" placeholder="请输入是否有配置，0未配置，1有配置" />
        </el-form-item>
        <el-form-item label="是否上传，0未上传1已上传" prop="uploadFlag">
          <el-input v-model="form.uploadFlag" placeholder="请输入是否上传，0未上传1已上传" />
        </el-form-item>
        <el-form-item label="是否确认过，0未确认1已确认" prop="confirmFlag">
          <el-input v-model="form.confirmFlag" placeholder="请输入是否确认过，0未确认1已确认" />
        </el-form-item>
        <el-form-item label="发布内容" prop="publishText">
          <el-input v-model="form.publishText" placeholder="请输入发布内容" />
        </el-form-item>
        <el-form-item label="生产人姓名" prop="createdName">
          <el-input v-model="form.createdName" placeholder="请输入生产人姓名" />
        </el-form-item>
        <el-form-item label="修改人姓名" prop="updatedName">
          <el-input v-model="form.updatedName" placeholder="请输入修改人姓名" />
        </el-form-item>
        <el-form-item label="业务线" prop="businessLine">
          <el-input v-model="form.businessLine" placeholder="请输入业务线" />
        </el-form-item>
        <el-form-item label="业务对接人" prop="businessContactPerson">
          <el-input v-model="form.businessContactPerson" placeholder="请输入业务对接人" />
        </el-form-item>
        <el-form-item label="测试结果" prop="testResult">
          <el-input v-model="form.testResult" placeholder="请输入测试结果" />
        </el-form-item>
        <el-form-item label="页面描述" prop="pageDescription">
          <el-input v-model="form.pageDescription" placeholder="请输入页面描述" />
        </el-form-item>
        <el-form-item label="离线包url" prop="offlineUrl">
          <el-input v-model="form.offlineUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="离线包名" prop="offline">
          <el-input v-model="form.offline" placeholder="请输入离线包名" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/configInfo";
import Editor from '@/components/Editor';

export default {
  name: "configInfo",
  components: { Editor },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 适老化表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appId: null,
        pageName: null,
        url: null,
        fileName: null,
        fileContent: null,
        uploadPath: null,
        createdDate: null,
        createdBy: null,
        updatedBy: null,
        isHaveConfig: null,
        uploadFlag: null,
        confirmFlag: null,
        publishText: null,
        createdName: null,
        updatedName: null,
        businessLine: null,
        businessContactPerson: null,
        testResult: null,
        pageDescription: null,
        offlineUrl: null,
        offline: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        appId: [
          { required: true, message: "应用id不能为空", trigger: "blur" }
        ],
        fileName: [
          { required: true, message: "文件名不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询适老化列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        appId: null,
        systemId: null,
        systemName: null,
        appName: null,
        pageId: null,
        pageName: null,
        appKey: null,
        url: null,
        fileName: null,
        version: null,
        fileContent: null,
        uploadPath: null,
        createdDate: null,
        createdBy: null,
        updatedBy: null,
        isHaveConfig: null,
        uploadFlag: null,
        confirmFlag: null,
        publishText: null,
        createdName: null,
        updatedName: null,
        businessLine: null,
        businessContactPerson: null,
        testResult: null,
        pageDescription: null,
        offlineUrl: null,
        offline: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加适老化";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改适老化";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除适老化编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有适老化数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
